<?php
FLEA::loadClass('FLEA_Db_TableDataGateway');

class	Model_ActionEvent	extends		FLEA_Db_TableDataGateway
{
	var		$tableName		=	'actionevent';
	var		$primaryKey		=	'ActionEventID';
	
	var	$types	=	array(
	
		
		"Assign invention"	=>	1 ,
		"Assign trademark"	=>	2,
		"Assign copyright"	=>	3,
		
		"Accept invention"	=>	4 ,
		"Accept trademark"	=>	5,
		"Accept copyright"	=>	6,
		
		"Add Client"	=>	7 
		
	);
	
	function	findFirmMatters($firmID)
	{
		$sql	=	'select client.*,user.* from actionevent ' .
					' left join client on actionevent.ClientID=client.ClientID ' .
					' left join user on client.UserID=user.UserID' .
					' where actionevent.FirmID='.$firmID.' and actionevent.type>=4 and actionevent.type<=7 ';
		
		return $this->findBySql($sql);
	}
	
	function	updateActionEvent($firmID,$clientID,$type1)
	{
		$tem	=	$this->find('FirmID='.$firmID.' and ClientID='.$clientID);
		if($tem['FirmID'] != $firmID)
		{
			$type	=	$this->types[$type1];
		
			$event['FirmID']	=	$firmID;
			$event['ClientID']	=	$clientID;
			$event['Type']		=	$type;
			$event['Date']		=	date("",time());
			
			return $this->create($event);
		}
		
	}
}
?>